﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using JwtAuthDemo.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace JwtAuthDemo.Controllers
{
    [Authorize]
    [Route("[controller]")]
    public class BaseController : ControllerBase
    {

        public User GetCurrentUser
        {
            get
            {
                User user = new User();

                var claimsIdentity = this.User.Identity as ClaimsIdentity;

                var userId = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier)?.Value;
                var username = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                var MobilePhone = claimsIdentity.FindFirst(ClaimTypes.MobilePhone)?.Value;
                var Role = claimsIdentity.FindFirst(ClaimTypes.Role)?.Value;

                user.Id = int.Parse(userId);
                user.UserName = username;
                user.LastName = MobilePhone;
                user.FirstName = Role;

                return user;
            }
        }

        //var claimsIdentity = this.User.Identity as ClaimsIdentity;
       
    }
}